package com.thm.tfast.modules.sys.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.thm.tfast.core.entity.ViewResult;
import com.thm.tfast.modules.sys.model.SysDict;
import com.thm.tfast.modules.sys.model.vo.log.LogVo;
import com.thm.tfast.modules.sys.service.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 日志表 前端控制器
 * </p>
 *
 * @author THM
 * @since 2022-10-31
 */
@RestController
@Api(tags = "系统：日志管理")
@RequestMapping("/sysLog")
public class SysLogController {

    @Resource
    private SysLogService sysLogService;

    @ApiOperation("根据条件分页获取日志列表")
    @GetMapping(value = "/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键字：日志标题"),
            @ApiImplicitParam(name = "type", value = "日志类型"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true)
    })
    public ViewResult<Page<LogVo>> page(@RequestParam(value = "keyword", required = false) String keyword,
                                          @RequestParam(value = "type", required = false) Integer type,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<LogVo> page = sysLogService.page(keyword, type, pageNum, pageSize);
        return ViewResult.success(page);
    }

    @ApiOperation("获取指定日志信息")
    @GetMapping("/{logId}")
    public ViewResult<LogVo> getById(@PathVariable Long logId) {
        LogVo logVo = sysLogService.getLogById(logId);
        return ViewResult.success(logVo);
    }
}

